package com.xiaoxu.yihaoShop.visitDeep;

import com.xiaoxu.utils.LogParser;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.Map;


public class SessionIdMap extends Mapper<LongWritable, Text,Text,LongWritable> {

    LongWritable ONE;

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        ONE = new LongWritable(1);
    }

    /**
     *
     * @param key  偏移量
     * @param value  106.3.114.42	中国	北京市	-	3T4QEMG2BQ93ATS98JE9SZDBQ8VVEZMR	2013-07-21 11:24:56	-	http://www.yihaodian.com/2/?tracker_u=10325451727&tg=boomuserlist%3A%3A2463680&pl=www.61baobao.com&creative=30392663360&kw=&gclid=CPC2idPRv7gCFQVZpQodFhcABg&type=2
     * @param context 上下文，存储中间变量
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String log = value.toString();
        Map<String, String> logInfo = LogParser.parseAfterETL(log);

        String sessionId = logInfo.get("sessionId");

        context.write(new Text(sessionId),ONE);

    }
}
